package com.aier.classes.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.classes.entity.RequestParent;
import com.aier.classes.entity.RequestTeacher;
import com.aier.classes.service.IInviteRequestService;
import com.aier.common.dao.ICommonDAO;
import com.aier.user.service.IUserService;

@Scope("prototype")
@Component("classesMemberAuditAction")
public class ClassesMemberAuditAction extends ClassesBaseAction{

    /**
     * 班级管理-班级成员审核
     */
    private static final long serialVersionUID = 1L;

    @Resource(name = "inviteRequestService")
    private IInviteRequestService inviteRequestService;    
    @Resource(name = "userService")
    private IUserService userService;        
    
    private int s;                //成功:1 ,失败:0
    private String error_info;    //错误提示信息
        
    
    private List<RequestTeacher> requestTeacherList;    //教师申请记录列表    
    private List<RequestParent> requestParentList;        //家长申请记录列表
    private Long cid;            //班级id
    private Long tid;            //审核教师id
    private Long rtid;            //教师申请记录id
    private Long rpid;            //家长申请记录id
    private Short state;        //审核状态
    private Integer uid;     //用户ID
    
    

	private Integer sid;     //学校ID
    private int page;            //页数
    private int page_size;        //每页的记录数
    private int page_count;        //总页数
    private int count;            //总数
    private  List<Object>  requestlist;
//========================================================================================    
    
    @Override
    public String execute(){
        return SUCCESS;
    }

    /**
     * 查询班级教师申请记录列表(未审核的)
     * @return
     */
    @SuppressWarnings("unchecked")
    public String searchRequestTeacherList(){
        s = 0;    
        if(page<=0){
            page=1;
        }
        Map<String,Object> map = inviteRequestService.searchRequestTeacherList(
                page, page_size, cid, null,(short) 0);
        if(null!=map){
            requestTeacherList = (List<RequestTeacher>) map.get(ICommonDAO.OBJ_LIST);
            if (null != requestTeacherList) {
                for(RequestTeacher rt:requestTeacherList){
                    rt.setUser(userService.getUserByUid(rt.getUid()));
                }
               
            }
            page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
            count = (Integer) map.get(ICommonDAO.COUNT);
            page = (Integer) map.get(ICommonDAO.PAGE);
        }
        s = 1;
        return SUCCESS;
    }

    /**
     * 删除班级教师申请
     */
    public String deleteRequestTeacher(){
        s = inviteRequestService.deleteRequestTeacher(rtid);
        return SUCCESS;
    }
    
    /**
     * 审核班级教师申请
     */
    public String updateRequestTeacherState(){
        s = inviteRequestService.updateRequestTeacher(rtid, state,tid);
        return SUCCESS;
    }
    
//========================================================================================    
    
    /**
     * 查询班级家长申请记录列表
     * @return
     */
    @SuppressWarnings("unchecked")
    public String searchRequestParentList(){
        s = 0;    
        Map<String,Object> map = inviteRequestService.searchRequestParentList(page, page_size, cid,(short)0);
        if(null!=map){
            requestParentList = (List<RequestParent>) map.get(ICommonDAO.OBJ_LIST);
            if (null != requestParentList) {
                for(RequestParent rp:requestParentList){
                    rp.setUser_parent(userService.getUserByUid(rp.getParent_uid()));
                }
                s = 1;
            }
            page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
            count = (Integer) map.get(ICommonDAO.COUNT);
            page = (Integer) map.get(ICommonDAO.PAGE);
        }
        return SUCCESS;
    }

    /**
     * 删除班级家长申请
     */
    public String deleteRequestParent(){
        s = inviteRequestService.deleteRequestParent(rpid);
        return SUCCESS;
    }
    
    /**
     * 审核班级家长申请
     */
    public String updateRequestParentState(){
        s = inviteRequestService.updateRequestParent(rpid, state,cid);
        return SUCCESS;
    }
    
    /**
     * 获取是否审核中
     * @return
     */
    public String requestTeacherListByState(){
    	requestlist=inviteRequestService.requestTeacherListByState(sid,uid);
    	s=1;
    	return SUCCESS;
    }
//======================================================================================== 
    

    public int getPage_count() {
        return page_count;
    }

    public int getCount() {
        return count;
    }

    public int getS() {
        return s;
    }

    public String getError_info() {
        return error_info;
    }

    public List<RequestTeacher> getRequestTeacherList() {
        return requestTeacherList;
    }

    public List<RequestParent> getRequestParentList() {
        return requestParentList;
    }

    public void setInviteRequestService(IInviteRequestService inviteRequestService) {
        this.inviteRequestService = inviteRequestService;
    }

    public void setCid(Long cid) {
        this.cid = cid;
    }

    public void setTid(Long tid) {
        this.tid = tid;
    }

    public void setRtid(Long rtid) {
        this.rtid = rtid;
    }

    public void setRpid(Long rpid) {
        this.rpid = rpid;
    }

    public void setState(Short state) {
        this.state = state;
    }

    public Long getCid() {
        return cid;
    }

    public Long getTid() {
        return tid;
    }

    public void setUserService(IUserService userService) {
        this.userService = userService;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public void setPage_size(int page_size) {
        this.page_size = page_size;
    }

    public int getPage() {
        return page;
    }

	public List<Object> getRequestlist() {
		return requestlist;
	}

	public void setSid(Integer sid) {
		this.sid = sid;
	}

  
    
	public void setUid(Integer uid) {
		this.uid = uid;
	}
    
    
    
    
    
    
}